<?php

namespace app\v1\controller;

use app\data\logic\JobLogic;
use app\data\service\JobdepartmentService;
use app\v1\BaseController;
use think\App;

class Jobdepartment extends BaseController
{
    protected $logic;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->logic = new JobLogic();
    }


    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $result = $this->logic->getJobDepartmentList($this->request->param());
        return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'), $result['list'], $result['count']);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param \think\Request $request
     * @return \think\Response
     */
    public function save()
    {
        //
        $param = $this->request->param();
        $result = $this->logic->createNewJobDepartment($param);
        if ($result['state']) {
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'));
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }

    /**
     * 显示指定的资源
     *
     * @param int $id
     * @return \think\Response
     */
    public function read($id)
    {
        $result = $this->logic->getJobDepartmentDetail($id);
        if ($result['state']) {
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'), $result['data']);
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param int $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param \think\Request $request
     * @param int $id
     * @return \think\Response
     */
    public function update($id)
    {
        $param = $this->request->param();
        if ($param['id']) {
            unset($param['id']);
        }

        $result = $this->logic->updateJobDepartment($id, $param);
        if ($result['state']) {
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'));
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }

    /**
     * 删除指定资源
     *
     * @param int $id
     * @return \think\Response
     */
    public function delete($id)
    {
        $result = $this->logic->deleteJobDepartment($id);
        if ($result['state']) {
            return $this->respMsg(\config('code.SUCCESS'), \lang('SUCCESS'));
        } else {
            return $this->respMsg(\config('code.FAILURE'), \lang('FAILURE'));
        }
    }
}